<?php
namespace Admin\Controller;
use Think\Controller;
class BulletinController extends BaseController {
    //公告列表
    public function bulletinList(){
         $re=M('')->query('select *,if(status=1,"隐藏","显示") as status,FROM_UNIXTIME(addtime, "%Y-%m-%d %H:%i:%S") as addtime from gm_bulletin');
        $data=$this->showPage($re);
        $this->assign('adminList',$data['arr']);
        $this->assign('page',$data['pageStr']);
        $this->display();
    }
    //添加公告
    public function bulletinAdd(){
        $id=I('get.id');

        if ($id) {
            $re=M('Bulletin')->where('id='.$id)->find();
            $this->assign('bulletin',$re);
        }
        $this->display();
    }
    //添加公告数据保存
    public function bulletinSave(){
        $data=I('post.');
        $id=I('get.id');
        if ($id) {
            $data['modify_time']=time();
            $re=M('Bulletin')->where('id='.$id)->save($data);
        }else{
            $data['addtime']=time();
            $re=M('Bulletin')->add($data);
        }
        if ($re) {
            $this->ajaxReturn('success');
        }else{
            $this->ajaxReturn('false');
        }
    }
    //删除公告
    public function del(){
        $id=I('get.id');
        $re=M('Bulletin')->where('id='.$id)->delete();
        if ($re) {
            $this->ajaxReturn('success');
        }else{
            $this->ajaxReturn('false');
        }
    }
}